package thread_01;
//懒汉，不是在程序启动时创建实例，而是在第一次使用时创建
class SingletonLazy{
    private static volatile SingletonLazy instance = new SingletonLazy();

    public static SingletonLazy getInstance(){
        Object locker = new Object();
        if (instance == null){
            synchronized (locker){
                if (instance==null){
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }

    private SingletonLazy(){
    }
}

public class Demo28 {
    public static void main(String[] args) {
        SingletonLazy s1 = SingletonLazy.getInstance();
        SingletonLazy s2 = SingletonLazy.getInstance();
        System.out.println(s1==s2);
    }
}
